/*jadclipse*/// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.

package nc.ui.pf.change;

import java.util.Date;
import nc.bs.logging.Logger;
import nc.ui.pf.pub.PfUIDataCache;
import nc.ui.pub.ClientEnvironment;
import nc.ui.pub.linkoperate.ILinkQueryData;
import nc.ui.pub.pf.IUINodecodeSearcher;
import nc.vo.bd.CorpVO;
import nc.vo.jcom.lang.StringUtil;
import nc.vo.pf.change.IchangeVO;
import nc.vo.pf.change.PfUtilBaseTools;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.billtype.BilltypeVO;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.sm.UserVO;
import nc.vo.uap.pf.PFBusinessException;

// Referenced classes of package nc.ui.pf.change:
//            VOConversionUI

public class PfUtilUITools extends PfUtilBaseTools
{

    public PfUtilUITools()
    {
    }

    private static AggregatedValueObject pfInitVoClass(String billType, int iChildLength)
        throws BusinessException
    {
        String billInfo[] = PfUIDataCache.getStrBillVo(billType);
        String strBillVoClassName = billInfo[0];
        String strHeadVoClassName = billInfo[1];
        String strItemVoClassName = billInfo[2];
        AggregatedValueObject retObj = pfInitVo(strBillVoClassName, strHeadVoClassName, strItemVoClassName, iChildLength);
        return retObj;
    }

    private static AggregatedValueObject[] pfInitVosClass(String billType, AggregatedValueObject sourceBillVOs[])
        throws BusinessException
    {
        String billInfo[] = PfUIDataCache.getStrBillVo(billType);
        String strBillVoClassName = billInfo[0];
        AggregatedValueObject retVos[] = null;
        retVos = pfInitVos(strBillVoClassName, sourceBillVOs.length);
        for(int i = 0; i < sourceBillVOs.length; i++)
            retVos[i] = pfInitVoClass(billType, sourceBillVOs[i].getChildrenVO().length);

        return retVos;
    }

    public static AggregatedValueObject runChangeData(String sourceBillType, String destBillType, AggregatedValueObject sourceBillVO)
        throws BusinessException
    {
        if(sourceBillVO == null)
            return null;
        Logger.debug((new StringBuilder()).append(">>\u5F00\u59CB\u5355\u636EVO\u4EA4\u6362=").append(sourceBillType).append("\u5230").append(destBillType).toString());
        AggregatedValueObject destBillVO = null;
        String strClassNameNoPackage = (new StringBuilder()).append("CHG").append(sourceBillType).append("TO").append(destBillType).toString();
        String uiChgClassName = (new StringBuilder()).append("nc.ui.pf.changedir.").append(strClassNameNoPackage).toString();
        Object changeImpl = null;
        try
        {
            changeImpl = findUIChangeScriptClass(sourceBillType, destBillType);
        }
        catch(Exception ex)
        {
            Logger.error(ex.getMessage(), ex);
            throw new PFBusinessException((new StringBuilder()).append("\u524D\u53F0VO\u4EA4\u6362\u5931\u8D25\uFF0C\u627E\u4E0D\u5230\u4EA4\u6362\u7C7B=").append(uiChgClassName).toString());
        }
        if(changeImpl instanceof VOConversionUI)
        {
            VOConversionUI tmpVar = (VOConversionUI)changeImpl;
            initConversionEnv(tmpVar);
        }
        adjustBeforeVoMapping(destBillType, new AggregatedValueObject[] {
            sourceBillVO
        });
        AggregatedValueObject destVo = pfInitVoClass(destBillType, sourceBillVO.getChildrenVO().length);
        destBillVO = ((IchangeVO)changeImpl).retChangeBusiVO(sourceBillVO, destVo);
        adjustAfterVoMapping(sourceBillType, destBillType, new AggregatedValueObject[] {
            sourceBillVO
        }, new AggregatedValueObject[] {
            destBillVO
        });
        Logger.debug((new StringBuilder()).append(">>\u7ED3\u675F\u5355\u636EVO\u4EA4\u6362=").append(sourceBillType).append("\u5230").append(destBillType).toString());
        return destBillVO;
    }

    private static Object findUIChangeScriptClass(String sourceBillType, String destBillType)
        throws Exception
    {
        Logger.debug("\u67E5\u8BE2\u4EA4\u6362\u7C7B\u5F00\u59CB......");
        String strClassNameNoPackage = (new StringBuilder()).append("CHG").append(sourceBillType).append("TO").append(destBillType).toString();
        String fullyQualifiedClassName = (new StringBuilder()).append("nc.ui.pf.changedir.").append(strClassNameNoPackage).toString();
        BilltypeVO srcBilltypeVO = null;
        BilltypeVO destBilltypeVO = null;
        String srcParentBilltype = null;
        String destParentBilltype = null;
        Object changeImpl = null;
        try
        {
            Logger.debug((new StringBuilder()).append("1.\u5C1D\u8BD5\u5B9E\u4F8B\u5316\u7C7B=").append(fullyQualifiedClassName).toString());
            Class c = Class.forName(fullyQualifiedClassName);
            changeImpl = c.newInstance();
        }
        catch(Exception e1)
        {
            Logger.debug("\u5C1D\u8BD5\u67E5\u627E\u76EE\u7684\u5355\u636E\u7684\u7236\u5355\u636E\u7C7B\u578B");
            destBilltypeVO = PfUIDataCache.getBillType(destBillType);
            if(destBilltypeVO.getBillstyle() != null)
            {
                Logger.debug("\u627E\u5230\u76EE\u7684\u5355\u636E\u7684\u7236\u5355\u636E\u7C7B\u578B");
                destParentBilltype = PfUIDataCache.getBillTypeByStyle(destBilltypeVO.getBillstyle().toString());
                strClassNameNoPackage = (new StringBuilder()).append("CHG").append(sourceBillType).append("TO").append(destParentBilltype).toString();
                fullyQualifiedClassName = (new StringBuilder()).append("nc.ui.pf.changedir.").append(strClassNameNoPackage).toString();
                try
                {
                    Logger.debug((new StringBuilder()).append("2.\u5C1D\u8BD5\u5B9E\u4F8B\u5316\u7C7B=").append(fullyQualifiedClassName).toString());
                    Class c = Class.forName(fullyQualifiedClassName);
                    changeImpl = c.newInstance();
                }
                catch(Exception e2)
                {
                    Logger.debug("\u5C1D\u8BD5\u67E5\u627E\u6E90\u5355\u636E\u7684\u7236\u5355\u636E\u7C7B\u578B");
                    srcBilltypeVO = PfUIDataCache.getBillType(sourceBillType);
                    if(srcBilltypeVO.getBillstyle() != null)
                    {
                        Logger.debug("\u627E\u5230\u6E90\u5355\u636E\u7684\u7236\u5355\u636E\u7C7B\u578B");
                        srcParentBilltype = PfUIDataCache.getBillTypeByStyle(srcBilltypeVO.getBillstyle().toString());
                        strClassNameNoPackage = (new StringBuilder()).append("CHG").append(srcParentBilltype).append("TO").append(destBillType).toString();
                        fullyQualifiedClassName = (new StringBuilder()).append("nc.ui.pf.changedir.").append(strClassNameNoPackage).toString();
                        try
                        {
                            Logger.debug((new StringBuilder()).append("3.\u5C1D\u8BD5\u5B9E\u4F8B\u5316\u7C7B=").append(fullyQualifiedClassName).toString());
                            Class c = Class.forName(fullyQualifiedClassName);
                            changeImpl = c.newInstance();
                        }
                        catch(Exception e3)
                        {
                            strClassNameNoPackage = (new StringBuilder()).append("CHG").append(srcParentBilltype).append("TO").append(destParentBilltype).toString();
                            fullyQualifiedClassName = (new StringBuilder()).append("nc.ui.pf.changedir.").append(strClassNameNoPackage).toString();
                            Logger.debug((new StringBuilder()).append("4.\u5C1D\u8BD5\u5B9E\u4F8B\u5316\u7C7B=").append(fullyQualifiedClassName).toString());
                            Class c = Class.forName(fullyQualifiedClassName);
                            changeImpl = c.newInstance();
                        }
                    } else
                    {
                        throw new PFBusinessException("\u6E90\u5355\u636E\u65E0\u5355\u636E\u5927\u7C7B\uFF0C\u65E0\u6CD5\u83B7\u53D6\u5176\u7236\u5355\u636E\u7C7B\u578B");
                    }
                }
            } else
            {
                Logger.debug("\u76EE\u7684\u5355\u636E\u65E0\u5355\u636E\u5927\u7C7B\uFF0C\u5C1D\u8BD5\u67E5\u627E\u6E90\u5355\u636E\u7684\u7236\u5355\u636E\u7C7B\u578B");
                srcBilltypeVO = PfUIDataCache.getBillType(sourceBillType);
                if(srcBilltypeVO.getBillstyle() != null)
                {
                    srcParentBilltype = PfUIDataCache.getBillTypeByStyle(srcBilltypeVO.getBillstyle().toString());
                    strClassNameNoPackage = (new StringBuilder()).append("CHG").append(srcParentBilltype).append("TO").append(destBillType).toString();
                    fullyQualifiedClassName = (new StringBuilder()).append("nc.ui.pf.changedir.").append(strClassNameNoPackage).toString();
                    Logger.debug((new StringBuilder()).append("5.\u5C1D\u8BD5\u5B9E\u4F8B\u5316\u7C7B=").append(fullyQualifiedClassName).toString());
                    Class c = Class.forName(fullyQualifiedClassName);
                    changeImpl = c.newInstance();
                } else
                {
                    throw new PFBusinessException("\u9519\u8BEF\uFF1A\u6E90\u5355\u636E\u3001\u76EE\u7684\u5355\u636E\u90FD\u65E0\u5355\u636E\u5927\u7C7B");
                }
            }
        }
        Logger.debug("\u67E5\u8BE2\u4EA4\u6362\u7C7B\u7ED3\u675F......");
        return changeImpl;
    }

    public static AggregatedValueObject[] runChangeDataAry(String sourceBillType, String destBillType, AggregatedValueObject sourceBillVOs[])
        throws BusinessException
    {
        if(sourceBillVOs == null || sourceBillVOs.length == 0)
            return null;
        Logger.debug((new StringBuilder()).append(">>\u5F00\u59CB\u5355\u636EVO\u6279\u91CF\u4EA4\u6362=").append(sourceBillType).append("\u5230").append(destBillType).toString());
        AggregatedValueObject destBillVOs[] = null;
        String strClassNameNoPackage = (new StringBuilder()).append("CHG").append(sourceBillType).append("TO").append(destBillType).toString();
        String uiChgClassName = (new StringBuilder()).append("nc.ui.pf.changedir.").append(strClassNameNoPackage).toString();
        Object uiChgObj = null;
        try
        {
            uiChgObj = findUIChangeScriptClass(sourceBillType, destBillType);
        }
        catch(Exception ex)
        {
            Logger.error(ex.getMessage(), ex);
            throw new PFBusinessException((new StringBuilder()).append("\u524D\u53F0VO\u4EA4\u6362\u5931\u8D25\uFF0C\u627E\u4E0D\u5230\u4EA4\u6362\u7C7B=").append(uiChgClassName).toString());
        }
        if(uiChgObj instanceof VOConversionUI)
        {
            VOConversionUI tmpVar = (VOConversionUI)uiChgObj;
            initConversionEnv(tmpVar);
        }
        adjustBeforeVoMapping(destBillType, sourceBillVOs);
        AggregatedValueObject destVo[] = pfInitVosClass(destBillType, sourceBillVOs);
        destBillVOs = ((IchangeVO)uiChgObj).retChangeBusiVOs(sourceBillVOs, destVo);
        adjustAfterVoMapping(sourceBillType, destBillType, sourceBillVOs, destBillVOs);
        Logger.debug((new StringBuilder()).append(">>\u7ED3\u675F\u5355\u636EVO\u6279\u91CF\u4EA4\u6362=").append(sourceBillType).append("\u5230").append(destBillType).toString());
        return destBillVOs;
    }

    private static void initConversionEnv(VOConversionUI tmpVar)
    {
        tmpVar.setSysDate(ClientEnvironment.getInstance().getDate().toString());
        tmpVar.setSysOperator(ClientEnvironment.getInstance().getUser().getPrimaryKey());
        tmpVar.setSysAccountYear(ClientEnvironment.getInstance().getAccountYear());
        tmpVar.setSysCorp(ClientEnvironment.getInstance().getCorporation().getPk_corp());
        tmpVar.setSysTime((new UFDateTime(new Date())).toString());
    }

    public static String findCustomNodeOfBilltype(BilltypeVO btVO, ILinkQueryData lqd)
    {
        Logger.debug((new StringBuilder()).append("::\u67E5\u627E\u81EA\u5B9A\u4E49\u8282\u70B9 findCustomNodeOfBilltype=").append(btVO.getPrimaryKey()).toString());
        String strClassName = btVO.getDef3();
        Logger.debug((new StringBuilder()).append("::bd_billtype.def3=").append(strClassName).toString());
        if(StringUtil.isEmptyWithTrim(strClassName))
            return null;
        Object obj = null;
        try
        {
            Class c = Class.forName(strClassName);
            obj = c.newInstance();
        }
        catch(Exception e)
        {
            Logger.error(e.getMessage(), e);
        }
        if(obj instanceof IUINodecodeSearcher)
        {
            Logger.debug("::bd_billtype.def3\u5B9E\u73B0\u4E86\u63A5\u53E3IUINodecodeSearcher");
            return ((IUINodecodeSearcher)obj).findNodecode(lqd);
        } else
        {
            return null;
        }
    }

    public static String findNodecodeOfBilltype(String pkBilltype, ILinkQueryData lqd)
    {
        BilltypeVO btVO = PfUIDataCache.getBillType(pkBilltype);
        if(btVO == null)
            return null;
        String strClassName = btVO.getDef3();
        if(strClassName == null)
            return btVO.getNodecode();
        Object obj = null;
        try
        {
            Class c = Class.forName(strClassName);
            obj = c.newInstance();
        }
        catch(Exception e)
        {
            Logger.error(e.getMessage(), e);
        }
        if(obj instanceof IUINodecodeSearcher)
            return ((IUINodecodeSearcher)obj).findNodecode(lqd);
        else
            return btVO.getNodecode();
    }
}
